package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {

        try (
                Connection con = DBUtil.getConnection()
        ){
            Statement statement = con.createStatement();
            String sql = "select t.name,t.salary,t.title,c.name,c.floor " +
                         "from teacher t " +
                         "join class c on t.id=c.teacher_id " +
                         "where t.name='王克晶' ";

            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
//                String tName = rs.getString("t.name");
//                int tSalary = rs.getInt("t.salary");
//                String tTitle = rs.getString("t.title");
//                String cName = rs.getString("c.name");
//                int cFloor = rs.getInt("c.floor");

                String tName = rs.getString(1);
                int tSalary = rs.getInt(2);
                String tTitle = rs.getString(3);
                String cName = rs.getString(4);
                int cFloor = rs.getInt(5);
                System.out.println(tName + " " + tSalary + " " + tTitle + " " + cName + " " + cFloor);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }



    }
}
